package com.guqj.mq.activitemq.destination.composite;

import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.Session;

import com.guqj.mq.activitemq.ActiveMQFactory;

/**
 * 消息消费者
 * 
 * @author guqj
 * 
 */
public class JmsConsumer extends ActiveMQFactory {

	public static void messageConsume(String queue) {
		Session session = null;
		Connection connection = null;
		try {
			connection = createConnection();
			// 创建session
			session = connection.createSession(Boolean.FALSE,
					Session.AUTO_ACKNOWLEDGE);
			MessageConsumer messageConsumer = createConsumer(session, queue, "QUEUE");
			listenerMessage(messageConsumer, queue);
		} catch (JMSException e) {
			e.printStackTrace();
		} finally {
			closeSource(null, null);
		}
	}

	public static void main(String[] args) throws JMSException,
			InterruptedException {
		messageConsume("VirtualTopic.Orders");
		//messageConsume("Consumer.A.VirtualTopic.Orders");
		//messageConsume("Consumer.B.VirtualTopic.Orders");
		//messageConsume("Consumer.B.VirtualTopic.Orders");
	}
}
